home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
APP
/
A-D
/
Alpha.4.01.cpt
/
LaTeX
/
Using MPW
< prev
Wrap
Internet Message Format
|
1991-10-10
|
4KB
From @cunyvm.cuny.edu:MPARK@UTMEM1.BITNET Wed Oct 9 15:17:52 1991
Message-Id: <9110092017.AA19098@rice.edu>
Date: Wed, 9 Oct 91 15:16 CST
From: <MPARK%UTMEM1.BITNET@cunyvm.cuny.edu>
Subject: MPW ACMDs
To: pete@rice.edu
X-Original-To: pete@rice.edu, MPARK
Pete,
The following summarizes a few hours of working through how to
write an ACMD with MPW C.
Integers are 32 bits long in MPW C and passed as such in alert().
Therefore, use %ld and %lu to print integers as in:
alert("defining CMLCol as %ld\n(k is %ld)",n,k);
Declaring or casting the parameters to short does not work as the
standard conversion back to type int is done before passing them
to alert.
The other callback functions work as documented.
To add an ACMD using MPW, compile and link following the directions
for stand-alone code resources in the MPW C Compiler manual and
chapter 8 of the MPW Reference manual. Briefly, compile with the
-b option, so that all variables, including string constants, are
compiled into the same segment. Access to them is via PC-relative
addressing, so no special calls to create a dummy A5, or similar,
world, are necessary. Link as shown, with the -rt, -m, and -sg
options to name a the resource type and ID, specify the entry
point, and name the segment. This method restricts greatly the
number of library subroutines that can be used. More on how to
use the DRVRruntime library to solve this comes later.
The following code does nothing but create, modify, and display
an ACMD-defined variable.
/*---------------------------------------------------------------
VarACMD, a code segment to access an ACMD-defined variable.
Restrictions: Treatment of int as longs is MPW C specific.
Compile with:
C -b 'VarACMD.c'
Link with:
Link -t 'ACMD' -rt ACMD=128 -m main -sg VarACMD 6
'VarACMD.c.o' 6
#"{CLibraries}"CSANELib.o 6
#"{CLibraries}"Math.o 6
#"{CLibraries}"Complex.o 6
#"{CLibraries}"StdClib.o 6
#"{Libraries}"Runtime.o 6
#"{Libraries}"Interface.o 6
-o VarACMD
(Note that no libraries are needed for this little thing.)
M.R. Park
Univ. Tenn. Memphis
(901) 528-5984
MPARK@utmem1.utmem.edu
----------------------------------------------------------------*/
typedef int (*FPtr)();
int MyGlobal;
char *main(char *text,FPtr alert,FPtr getVar,
FPtr setVar, FPtr defVar, FPtr delVar)
{
int n,k;
if (!(k=getVar("CMLCol",&n))) {
defVar("CMLCol",n=1);
alert("defining CMLCol as %ld\n(k is %ld)",n,k);
}
MyGlobal=k;
alert("bumping CMLCol from %ld to %ld\n (k is %ld)",n,n+1,MyGlobal);
if(!setVar("CMLCol",n+1))
alert("Error\n");
return text;
}
/*--------------------------- END ------------------------------*/
In the Alpha HelpText, I suggest modifying the first line of the
explanation of each callback function:
1. /***********************************************
* *
* Returns the longword value of the variable *
2. /***********************************************
* *
* Set the longword value of the variable *
3. /************************************************
* *
* Define a longword variable named 'name' with *
4. /*******************************************
* *
* Delete a longword variable named 'name'. *
-Mel Park